package com.lc.afbx.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.PostWoYaoZixun;
import com.lc.afbx.util.MyToast;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/5/23.
 */
public class ConsultationWantActivity extends BaseActivity implements View.OnClickListener {

    private EditText consultation_want_et;

    private PostWoYaoZixun postWoYaoZixun = new PostWoYaoZixun(new AsyCallBack<PostWoYaoZixun.Info>() {
        @Override
        public void onSuccess(String toast, int type, PostWoYaoZixun.Info info) throws Exception {

            UtilToast.show(ConsultationWantActivity.this, "提交成功");
            finish();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consultation_want);


        consultation_want_et = ((EditText) findViewById(R.id.consultation_want_et));

        consultation_want_et.addTextChangedListener(new TextWatcher() {
            private CharSequence temp = "";
            private int MAXLENGTH = 200;

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                temp = s;
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                if (temp.length() >= MAXLENGTH) {
                    MyToast.showToast("您输入的字数已经到达200", context);
                }
            }
        });

    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.consultation_want_bt:

                String question = consultation_want_et.getText().toString().trim();

                if (TextUtils.isEmpty(question)) {
                    MyToast.showToast("问题不能为空", context);
                    return;
                }

                postWoYaoZixun.userid = BaseApplication.BasePreferences.readUserId();
                postWoYaoZixun.title = question;
                postWoYaoZixun.execute(this);
                return;

        }


    }


}
